package pl.cba.solgar.game.rogal.map.tiles;

import java.util.Random;
import java.util.Vector;

import org.newdawn.slick.Color;

public class AbstractTile
{
	final public static String PROPERTY_WATER_DEEP    = "deep_water";
	final public static String PROPERTY_WATER_SHALLOW = "shallow_water";
	final public static String PROPERTY_WATER_PUDDLE  = "puddle_water";

	final public static String TILE_CAVE_WALL     = "cave_wall";
	final public static String TILE_CAVE_FLOOR    = "cave_floor";
	final public static String TILE_OUTDOOR_GRASS = "outdoor_grass";
	final public static String TILE_DEEP_WATER    = "deep_water";

	protected String		tileTypeName = null;
	protected char[]		tileChar = {'?'};
	public Color[]		background = { Color.red };
	protected String		tileCharString = "" + new String(tileChar);
	protected Color[]		tileColor = { Color.white };
	protected int			animationFrame = 0;
	protected boolean       walkable = true;

	private static Random random;

	private Vector<String>	properties;

	public AbstractTile(String name)
	{
		if (random == null)
			 random = new Random(System.currentTimeMillis());

		tileTypeName = name;

		if (name == TILE_CAVE_WALL)
		{
			tileChar = new char[]{'#'};
			tileColor = new Color[] { Color.gray };
			background = new Color[] { Color.black };
			walkable = false;
		}
		else if (name == TILE_CAVE_FLOOR)
		{
			tileChar = new char[]{'.'};
			tileColor = new Color[] { Color.gray };
			background = new Color[] { Color.black };
		}
		else if (name == TILE_OUTDOOR_GRASS)
		{
			tileChar = new char[]{'.'};
			tileColor = new Color[] { Color.green };
			background = new Color[] { Color.black };
		}
		else if (name == TILE_DEEP_WATER)
		{
			tileChar = new char[] {'~', '~', '~', '~', '~', '~'};
			tileColor = new Color[] { Color.black, Color.blue, Color.cyan, Color.darkGray, Color.green, Color.magenta };
			background = new Color[] { Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow };
			animationFrame = random.nextInt(tileChar.length);
			walkable = false;
		}

		tileCharString = "" + new String(tileChar);
	}

	public void nextFrame()
	{
		animationFrame += 1;
		if (animationFrame >= tileChar.length)
			animationFrame = 0;
	}

	public AbstractTile(String name, char _char, Color color)
	{
		tileTypeName = name;
		tileChar = new char[]{ _char };
		tileCharString = "" + new String(tileChar);
		tileColor = new Color[] { color };
	}

	public boolean isWalkable()
	{
		return walkable;
	}

	public String getTypeName()
	{
		return tileTypeName;
	}

	public char getChar()
	{
		return tileChar[animationFrame];
	}

	public String getCharString()
	{
		return tileCharString;
	}

	public Color getColor()
	{
		return tileColor[animationFrame];
	}

	public Color getBackbroundColor()
	{
		return background[animationFrame];
	}
}
